#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
const int maxn = 1e5+10;
ll a[maxn];
ll at[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		ll minn = 1e18;
		for(int i = 1;i<=n;i++)
		{
			cin>>a[i];
			at[i] = a[i];
		}
		sort(at+1,at+1+n);
		minn = at[1];
		int flag = 0;
		for(int i = 1;i<=n;i++)
		{
			if(a[i]==at[i]) continue;
			if(a[i]%minn)
			{
				flag = 1;
				break;
			}
		}
		if(!flag) printf("YES\n");
		else printf("NO\n");
	}
	
} 
